package com.cupk.rotaryguard.monitor.utils;

import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author tjy
 */
public class GenrateFeatureData {

    private static final Pattern pattern = Pattern.compile("(\\d)=([\\d\\.]+)");

    public static void main(String[] args) throws Exception {
        String[][] featureStringMatrix = generateFeatureStringMatrix();
        String diagnosis = ClassificationModel.diagnosis(featureStringMatrix);
        System.out.println(diagnosis);

    }

    public static String[][] generateFeatureStringMatrix() {
        String[] headers = {"DE_time_std", "DE_time_ptp", "DE_time_skew", "DE_time_wavefactor", "DE_time_peakfactor",
                "DE_time_pulse", "DE_max1_point", "DE_max2_point", "DE_max3_point", "DE_max1_ratio",
                "DE_max2_ratio", "DE_max3_ratio", "DE_cA4", "DE_cD4", "DE_cD3", "DE_cD2", "DE_cD1",
                "FE_time_std", "FE_time_ptp", "FE_time_skew", "FE_time_wavefactor", "FE_time_peakfactor",
                "FE_time_pulse", "FE_max1_point", "FE_max2_point", "FE_max3_point", "FE_max1_ratio",
                "FE_max2_ratio", "FE_max3_ratio", "FE_cA4", "FE_cD4", "FE_cD3", "FE_cD2", "FE_cD1", "RPM", "filename"};
        String[][] simulatedData = new String[2][headers.length];
        simulatedData[0] = headers;

        Random rand = new Random();

        for (int i = 0; i < headers.length; i++) {
            double randomValue = -1.0 + 2.0 * rand.nextDouble();
            simulatedData[1][i] = String.format("%.15f", randomValue);
        }
        return simulatedData;
    }

    /**
     * 从得到的概率分布中得到对应数值返回list
     *
     * @param str
     * @return
     */
    public static Map<Integer, Double> getValuesFromDiagnosisDeviceProb(String str) {
        Map<Integer, Double> map = new HashMap<Integer, Double>();
        Matcher matcher = pattern.matcher(str);
        while (matcher.find()) {
            String keyStr = matcher.group(1);
            Integer key = Integer.parseInt(keyStr);
            String valueStr = matcher.group(2);
            Double value = Double.parseDouble(valueStr);
            map.put(key, value);
        }
        return map;
    }

}
